package ar.edu.unicen.exa.oop.bbquery.model.forum.content.filters;


public enum LogicalOperation {
    /**
     * These value is the most mind-f**ker value; with these, we can handle 
     * expressions like A -> (B -> (C -> D)) when using ContentFilter
     * inherited classes, Weird, no?.
     */
    IMPLIES {
	@Override
	public boolean calculate(boolean FirstValue, boolean SecondValue) {
	    return !FirstValue || SecondValue;
	}

	@Override
	public boolean getLeftNeutralValue() {
	    return true;
	}

	@Override
	public boolean getRightNeutralValue() {
	    return false;
	}
    },
    AND {
	@Override
	public boolean calculate(boolean FirstValue, boolean SecondValue) {
	    return FirstValue && SecondValue;
	}

	@Override
	public boolean getLeftNeutralValue() {
	    return true;
	}

	@Override
	public boolean getRightNeutralValue() {
	    return true;
	}
    },
    OR  {
	@Override
	public boolean calculate(boolean FirstValue, boolean SecondValue) {
	    return FirstValue || SecondValue;
	}

	@Override
	public boolean getLeftNeutralValue() {
	    return false;
	}

	@Override
	public boolean getRightNeutralValue() {
	    return false;
	}
    },
    XOR {
	@Override
	public boolean calculate(boolean FirstValue, boolean SecondValue) {
	    return FirstValue ^ SecondValue;
	}

	@Override
	public boolean getLeftNeutralValue() {
	    return false;
	}

	@Override
	public boolean getRightNeutralValue() {
	    return false;
	}
    };   
    /**
     * this op returns a boolean value, such that:
     * 	 V == calculate(getNeutralValue(),V).
     * @return true or false, this value depends from operation calculate.
     */
    public abstract boolean getLeftNeutralValue();
    
    /**
     * this op returns a boolean value, such that:
     * 	 V == calculate(V,getNeutralValue()).
     * @return true or false, this value depends from operation calculate.
     */
    public abstract boolean getRightNeutralValue();
    
    /**
     * 
     * Execute a binary operation, for example: OR, AND, XOR, etc ...
     * 
     * @param FirstValue
     * @param SecondValue
     * @return
     */
    public abstract boolean calculate(boolean FirstValue,boolean SecondValue);

}
